package com.api.shopapi.service.impl;

import com.api.shopapi.entity.Building;
import com.api.shopapi.entity.Room;
import com.api.shopapi.mapper.RoomMapper;
import com.api.shopapi.service.RoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("RoomServiceImplOne")
public class RoomServiceImpl implements RoomService {

    @Autowired
    private RoomMapper roomMapper;


    @Override
    public int insert(Room room) {
        return roomMapper.insert(room);
    }

    @Override
    public int updateByRoomCode(Room room) {
        return roomMapper.updateByRoomCode(room);
    }

    @Override
    public int deleteByRoomCode(String roomCode) {
        return roomMapper.deleteByRoomCode(roomCode);
    }

    @Override
    public List<Room> getListAll() {
        return roomMapper.getListAll();
    }

    @Override
    public Room getByRoomCode(String roomCode) {
        return roomMapper.getByRoomCode(roomCode);
    }

    @Override
    public Building getByRoomCodeToBuilding(String roomCode) {
        return roomMapper.getByRoomCodeToBuilding(roomCode);
    }


    @Override
    public Room getByNumber(String number, String buildingCode, String institutionCode) {
        return roomMapper.getByName(number,buildingCode,institutionCode);
    }

    @Override
    public List<Room> getListAllByInstitutionCode(String institutionCode) {
        return roomMapper.getListAllByInstitutionCode(institutionCode);
    }

    @Override
    public List<Room> getListByBuildingCode(String buildingCode) {
        return roomMapper.getListByBuildingCode(buildingCode);
    }

    @Override
    public PageInfo<Room> getPageList(int pageIndex, int pageSize, String institutionCode, int number, String buildingCode, String roomTypeCode, int status) {
        PageHelper.startPage(pageIndex, pageSize);
        List<Room> roomList = roomMapper.getPageList(institutionCode,number,buildingCode,roomTypeCode,status);
        PageInfo<Room> pageInfo = new PageInfo<Room>(roomList);
        return pageInfo;
    }

    @Override
    public List<Room> getListByBuildingCodeAndStatus0(String buildingCode) {
        return roomMapper.getListByBuildingCodeAndStatus0(buildingCode);
    }

    @Override
    public List<Room> getListByBuildingCodeAndNumAndStatusNot1(String buildingCode,int num) {
        return roomMapper.getListByBuildingCodeAndNumAndStatusNot1(buildingCode,num);
    }

    @Override
    public List<Room> getByInstitutionCodeAndStatusNot11(String institutionCode) {
        return roomMapper.getByInstitutionCodeAndStatusNot11(institutionCode);
    }

    @Override
    public List<Room> getListByBuildingCodeAndStatusNot1(String buildingCode) {
        return roomMapper.getListByBuildingCodeAndStatusNot1(buildingCode);
    }

    @Override
    public List<Room> getListInRoomTypePriceMonth(String institutionCode, double priceMonth) {
        return roomMapper.getListInRoomTypePriceMonth(institutionCode,priceMonth);
    }



    @Override
    public
    PageInfo<Room> pageByGovCode(int pageIndex, int pageSize, String governmentCode){
        PageHelper.startPage(pageIndex, pageSize);
        List<Room> roomList = roomMapper.listByGovCode(governmentCode);
        PageInfo<Room> pageInfo = new PageInfo<Room>(roomList);
        return pageInfo;
    }

}
